<?php

namespace Admin\Controller;

class SysnoticeController extends BaseController {

  public function index() {
    $sysnotice = M("Sysnotice")->order("date desc")->select();
    $this->assign('sysnotice',$sysnotice);
    $this->assign('num',count($sysnotice));
    $this->display();
  }
  public function detail(){
    $id = I("get.id");
    $sysnotice = M("Sysnotice")->where("id=$id")->select();
    $this->assign('sysnotice',$sysnotice);
    $this->display();
  }
  public function del(){
    $id = I("get.id");
    $sysnotice = M("Sysnotice")->where("id=$id")->delete();
    $this->success('删除成功', U('Sysnotice/index'));
  }
  public function add(){
    $this->assign('type','add');
    $this->display('detail');
  }

  public function done()
  {
    $sysnotice = M("Sysnotice");
    $id = I("post.thisid");
    $data['title'] = I("post.title");
    $data['content'] = I("post.content");
    $data['date'] = time();
    if($id>0){
      $res = $sysnotice->where("id = '$id'")->save($data);
      if ($res) {
        $this->success('修改成功', U('Sysnotice/index'));
      } else {
        $this->success('未做任何更改', U("Sys/index"));
      }
    }else{
      $res = $sysnotice->add($data);
      if ($res) {
        $u['close_msg'] = 0;
        M("User")->where("id > 0")->save($u);
        $this->success('添加成功', U('Sysnotice/index'));
      } else {
        $this->success('未做任何更改', U("Sys/index"));
      }
    }
  }

}
